home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / Bitmap Libraries 2.0 / BitMap.txt < prev   
Text File  |  1996-07-08  |  47KB  |  1,493 lines

  1. file BitMap.txt Copyright (C) 1996 by John Montbriand.  All Rights Reserved.
  2.  
  3. ABOUT BITMAP...
  4.  
  5.     Copyright (C) 1996 by John Montbriand.  All Rights Reserved.
  6.     
  7.     Distribute freely in areas where the laws of copyright apply.
  8.  
  9.     Use at your own risk.
  10.     
  11.     Do not distribute modified copies.
  12.  
  13.     These various BitMap libraries are for free!
  14.  
  15.  
  16. ABOUT THE AUTHOR...
  17.  
  18.     Comments, questions, or suggestions are always welcome.
  19.  
  20.     John Montbriand                tinyjohn@sasknet.sk.ca
  21.     P.O. Box. 1133
  22.     Saskatoon Saskatchewan Canada
  23.     S7K 3N2
  24.  
  25.  
  26. WHY IS IT FOR FREE?
  27.  
  28.     none of your business,
  29.     
  30.     but if you have some business for me,  I'll see what I can do..
  31.  
  32.  
  33. OUTLINE OF TOPICS
  34.  
  35.     BITMAPS, WHAT ARE THEY?
  36.     IMPLEMENTATION NOTES
  37.     MATERIALS
  38.     LEGAL STUFF
  39.     FURTHER REFERENCE
  40.     SERVICES PROVIDED (OVERVIEW)
  41.     BE CAREFUL (CAVEATS)
  42.     OTHER COOL THINGS YOU CAN DO
  43.     OVERVIEW OF ROUTINES
  44.     SPECIFIC ROUTINE DESCRIPTIONS
  45.  
  46.  
  47. BITMAPS, WHAT ARE THEY?
  48.     
  49.     Well, they're like little black and white computer screens in memory
  50.     that you can do drawing in before transfering the images you
  51.     draw on them to the screen.  Drawing things off screen and then
  52.     placing them on screen creates the feel of instantaneous, flicker
  53.     free drawing.
  54.     
  55.     BitMaps are a data structure used to store black and white images
  56.     off-screen.  You can use quickdraw to draw directly into bitmaps
  57.     and create images for placement on the screen, or you can take
  58.     images from the screen, place them in a bitmap, do various
  59.     transformations to them, and then put them back on the screen.
  60.     
  61.     QuickDraw GrafPorts draw into BitMap structures, and, as a matter
  62.     of fact, all screen drawing on early macintoshes was implemented
  63.     through BitMaps that were memory mapped to the screen hardware.
  64.     
  65.     The big advantage:  BitMaps provide a way to do simple high quality
  66.     graphics while at the same time requiring very little memory.
  67.  
  68.  
  69. IMPLEMENTATION NOTES
  70.  
  71.     This implementation stores each bitmap in a single, contiguous,
  72.     non-relocatable memory block refered to using a pointer.  The first
  73.     14 bytes of the memory block contain the Bitmap data structure,
  74.     while the remaining bytes are used to store the raster data.
  75.  
  76.  
  77. MATERIALS
  78.  
  79.     The BitMap format itself is the copyright property of Apple
  80.     computer and has been known to the public since 1983.
  81.     
  82.     The routines documented herein are the copyright property of
  83.     John Montbriand.  I am making these routines available to the
  84.     macintosh programming community because I feel it's about time
  85.     someone did!  They're fun, easy to use, and practical.  I hope
  86.     all who find them will use them well.
  87.  
  88.     Compiled and tested with MPW C, MWC, SC, MrC, and MPW PPC.
  89.  
  90.  
  91. LEGAL STUFF
  92.  
  93.     These libraries are provided for free and you may use them
  94.     in any program you make;  however, if you're particular about
  95.     having signed documentation that proves this fact in your posession
  96.     then, as I would like to ensure these libraries are widely used,
  97.     I would be glad provide such documents for you.
  98.     
  99.     I don't think this is entirly necessary, but I can understand
  100.     that some folks feel quite strongly about such issues and prefer
  101.     to do things in writing.
  102.     
  103.     If you would like for me to send you a signed document saying
  104.     that you have license to use these routines in your programs,
  105.     then send me a couple of bucks to cover postage and handling
  106.     and I'll send you back a signed letter saying you have license
  107.     to use these routines in any software you make.
  108.     
  109.     I think two or three dollars is fair as I don't really get a big
  110.     thrill out of printing stuff out and mailing it, and that's usually
  111.     enough to cover postage to anywhere in the world.  I s'pose you'd have
  112.     to figure out how much it would cost for me to mail a letter to you
  113.     from here in Canada.
  114.  
  115.  
  116. FURTHER REFERENCE
  117.  
  118.     BitMap.h and BitMap.c contain routines for accessing and manipulating
  119.     BitMap data stored in pointers.  For more information about BitMaps,
  120.     offscreen drawing, pointers, C, etc..  refer to the following sources:
  121.     
  122.     "Bitmaps" (2-9) in the "Basic QuickDraw" chapter of Inside Macintosh:
  123.     Imaging With QuickDraw by Apple Computer, Inc.  Addison-Wesley.
  124.         A discussion of the Bitmap data structure and how it applies to
  125.         GrafPorts.
  126.         
  127.     "Boolean Transfer Modes With 1-Bit Pixels" (3-8) in the "QuickDraw Drawing"
  128.     chapter of Inside Macintosh: Imaging With QuickDraw by Apple Computer,
  129.     Inc.  Addison-Wesley.
  130.         BitMaps are 1-Bit Pixel data structures.  This part discusses the
  131.         various transfer modes you can use while drawing into BitMaps.
  132.     
  133.     "Copying Bits Between Graphics Ports" (3-32) in the "QuickDraw Drawing"
  134.     chapter of Inside Macintosh: Imaging With QuickDraw by Apple
  135.     Computer, Inc.  Addison-Wesley.
  136.         A discussion of the Bitmap data structure and how it applies to
  137.         GrafPorts.
  138.         
  139.     "Copying Images" (3-112) in the "QuickDraw Drawing" chapter of
  140.     Inside Macintosh: Imaging With QuickDraw by Apple
  141.     Computer, Inc.  Addison-Wesley.
  142.         A discussion of the CopyBits routine and the various parameter
  143.         combinations you can use with it.  This is followed by
  144.         a discussion of the CopyMask routine.
  145.  
  146.     Technical note #163 "Adding Color With CopyBits" by Chris Derossi
  147.         A discussion of how to draw in colour using bitmaps.
  148.     
  149.     Technical note #193 "So Many Bitmaps, So Little Time" by Rick Blair
  150.         A look at the BitMapToRegion routine.
  151.     
  152.     Technical note #41 "Drawing Into an Offscreen Bitmap" by
  153.     Jim Friedlander & Ginger Jernigan
  154.         A talk about offscreen bitmaps, and how to use them.
  155.     
  156.     Inside Macintosh: Memory by Apple Computer, Inc.  Addison-Wesley.
  157.         A discussion of memory managment, pointers, what they are, and
  158.         how to use them.
  159.     
  160.     The C Programming Language 2nd edition by Brian W. Kernighan
  161.         and Dennis M. Ritchie.  Prentice Hall.
  162.     
  163.     Comments for the routines provided herein have been included in the
  164.     file BitMap.h.
  165.     
  166.     Also, there is a 411 help file.
  167.     
  168.  
  169. SERVICES PROVIDED (OVERVIEW)
  170.  
  171.     - routines for creating bitmap structures in memory.
  172.     
  173.     - rotate functions for rotating bitmaps 90 degrees left and right,
  174.     
  175.     - flip functions for flipping bitmap data both vertically
  176.     and horizontally,
  177.     
  178.     - a trace edges routine for tracing the edges of an image,
  179.     
  180.     - a rotation routine for rotating a bitmap to a particular angle,
  181.     
  182.     - a routine for duplicating bitmaps,
  183.     
  184.     - a routine for comparing bitmaps,
  185.     
  186.     - routines providing the painbucket tool and lasso tool effects,
  187.     
  188.     - transfer routines for transfering bitmap data to and from the
  189.     PICT format,
  190.     
  191.     - a complete set of logical operations on bitmaps,
  192.     
  193.     - a complete set of pixel oriented routines for testing, setting,
  194.     clearing, and toggling individual pixels in bitmaps,
  195.     
  196.     - routines and a macro allowing you to quickly and easily draw
  197.     into bitmaps,
  198.     
  199.     - routines for copying bitmap images to the current grafport,
  200.  
  201.  
  202. BE CAREFUL (CAVEATS)
  203.  
  204.     I think these routines are safe to use, but you should do your own
  205.     testing.  I have provided the source code, and if you find any bugs,
  206.     please let me know right away so I can provide corrections in
  207.     future versions.
  208.     
  209.     I advertise a finder's fee of $10.00 cash for errors in any
  210.     of my products.
  211.  
  212.  
  213. OTHER COOL THINGS YOU CAN DO
  214.  
  215.     bitmaps provide a convenient, storage efficient way to
  216.     implement zero - one adjacency matrices that are incredibly
  217.     useful for working with directed graphs.
  218.  
  219.  
  220. OVERVIEW OF ROUTINES
  221.  
  222.     creating your own bitmaps:
  223.         BitMap* NewBitMap(short width, short height);
  224.         void KillBitMap(BitMap* bits);
  225.     
  226.     rotating a bitmap image 90 degrees to the left or to the right:
  227.         BitMap* RotateRight(BitMap* bits);
  228.         BitMap* RotateLeft(BitMap* bits);
  229.    
  230.     flipping a bitmap image horizontally or vertically:
  231.         BitMap* FlipVertical(BitMap* bits);
  232.         BitMap* FlipHorizontal(BitMap* bits);
  233.    
  234.     rotating a bitmap image to a particular angle:
  235.         BitMap* RotateBitMap(BitMap* bits, short cx, short cy, Fixed angle);
  236.  
  237.     duplicating a bitmap:
  238.         BitMap* DuplicateBitMap(BitMap* bits);
  239.         
  240.     the paint bucket function:
  241.         BitMap* PaintBucketBitMap(BitMap* bits, short h, short v);
  242.     
  243.     the lasso function:
  244.         BitMap* LassoBitMap(BitMap* bits);
  245.  
  246.     the trace edges function:
  247.         BitMap* TraceBitMap(BitMap* bits);
  248.  
  249.     transfer functions for converting to and from the PICT format:
  250.         BitMap* PICTToBitMap(PicHandle pic);
  251.         PicHandle BitMapToPICT(BitMap* bits);
  252.     
  253.     logical operations on bitmaps:
  254.         BitMap* BitMapAND(BitMap* a, BitMap* b);
  255.         BitMap* BitMapOR(BitMap* a, BitMap* b);
  256.         BitMap* BitMapXOR(BitMap* a, BitMap* b);
  257.         BitMap* BitMapNOT(BitMap* a);
  258.     
  259.     comparison:
  260.         Boolean EqualBitMaps(BitMap* a, BitMap* b);
  261.     
  262.     pixel oriented functions:
  263.         Boolean BitMapTest(BitMap* bits, short h, short v);
  264.         void BitMapSet(BitMap* bits, short h, short v);
  265.         void BitMapClear(BitMap* bits, short h, short v);
  266.         Boolean BitMapToggle(BitMap* bits, short h, short v);
  267.     
  268.     routines for drawing into bitmaps:
  269.         BitMapPort* NewBMP(BitMap* bits);
  270.         void DisposeBMP(BitMapPort* bmp);
  271.         #define WithBitMap(bits, bmp)    
  272.  
  273.     routines for copying bitmap data:
  274.         void PlotBitMap(BitMap* bits, short h, short v);
  275.  
  276.     a routine for converting pascal strings into bitmaps:
  277.         BitMap* StringToBitMap(short font, short size, short face, StringPtr s);
  278.         
  279.         
  280. SPECIFIC ROUTINE DESCRIPTIONS
  281.  
  282.  
  283. NewBitMap
  284.  
  285.     formal declaration:
  286.         BitMap* NewBitMap(short width, short height);
  287.     
  288.     arguments:
  289.         width     the width of the requested bitmap
  290.         height    the height of the requested bitmap
  291.     
  292.     return value:
  293.         a pointer to a Bitmap data structure. 
  294.         if an error occurs, NULL is returned.
  295.         
  296.     description:
  297.         NewBitMap creates a new bitmap pointer with the requested
  298.         dimensions.  The raster data is initialized to zeros, and if
  299.         there is not enough memory to allocate the bitmap, NewBitMap
  300.         will return NULL.
  301.         
  302.     example application:
  303.         The following creates a new bitmap pointer 100 pixels wide
  304.         and 200 pixels tall.
  305.         
  306.         {   BitMap *the_bits;
  307.             
  308.             the_bits = NewBitMap(100, 200);
  309.             ...
  310.             
  311.     notes:
  312.         You can call DisposePtr to dispose of a bitmap pointer created by
  313.         NewBitMap.  The routine KillBitMap calls DisposePtr.
  314.  
  315.  
  316. KillBitMap
  317.  
  318.     formal declaration:
  319.         void KillBitMap(BitMap* bits);
  320.     
  321.     arguments:
  322.         bits    a bitmap pointer
  323.     
  324.     return value:
  325.         none.
  326.         
  327.     description:
  328.         KillBitMap disposes of a bitmap pointer allocated by one of:
  329.         
  330.         NewMacPaintBitMap, NewBitMap, RotateRight, RotateLeft, FlipVertical,
  331.         FlipHorizontal, RotateBitMap, DuplicateBitMap, PaintBucketBitMap,
  332.         LassoBitMap, PICTToBitMap, BitMapAND, BitMapOR, BitMapXOR, or BitMapNOT.
  333.         
  334.         It's your general all purpose bitmap pointer disposal function.
  335.  
  336.     example application:
  337.         The following creates a new bitmap pointer 100 pixels wide
  338.         and 200 pixels tall and then disposes of it by calling KillBitMap.
  339.         
  340.         {   BitMap *the_bits;
  341.             
  342.             the_bits = NewBitMap(100, 200);
  343.             if (the_bits != NULL) {
  344.             
  345.                 KillBitMap(the_bits);
  346.             }
  347.             
  348.     notes:
  349.         KillBitMap simply calls DisposePtr.
  350.  
  351.  
  352. RotateRight
  353.  
  354.     formal declaration:
  355.         BitMap* RotateRight(BitMap* bits);
  356.     
  357.     arguments:
  358.         bits    a bitmap pointer
  359.     
  360.     return value:
  361.         a newly created bitmap pointer containing the image
  362.         from the bitmap pointer parameter rotated 90 degrees
  363.         to the right. 
  364.         if an error occurs, RotateRight will return the value NULL.
  365.         
  366.     description:
  367.         RotateRight creates a new bitmap containing the image
  368.         stored in the parameter bitmap pointer rotated 90 degrees
  369.         to the right.  The resulting bitmap is appropriately sized:
  370.         i.e. if the source bitmap is 100 pixels wide and 200 pixels tall,
  371.         then the result bitmap pointer will be 200 pixels wide and 100
  372.         pixels tall.  
  373.  
  374.     example application:
  375.         The example creates a new bitmap pointer containing the image
  376.         stored in the original bitmap rotated 90 degrees to the right
  377.         before copying the image to the current grafport.
  378.         
  379.         {   BitMap *the_bits;
  380.             BitMap *rotated_bits;
  381.             Rect bounds;
  382.             
  383.             the_bits = NewBitMap(100, 200);
  384.             if (the_bits != NULL) {
  385.             
  386.                 /* here we would draw something into the_bits */
  387.                 
  388.                 rotated_bits = RotateRight(the_bits);
  389.                 
  390.                 if (rotated_bits != NULL) {
  391.                     bounds = (*rotated_bits)->bounds;
  392.                     PlotMap(rotated_bits, 0, 0, srcCopy);
  393.                     KillBitMap(rotated_bits);
  394.                 }
  395.  
  396.                 KillBitMap(the_bits);
  397.             }
  398.             
  399.     notes:
  400.         RotateRight takes advantage of certain addressing and indexing
  401.         possibilities offered by the arrangement of the raster data
  402.         in memory.  It is faster than calling RotateBitMap and specifying
  403.         a 90 degree angle.
  404.  
  405.  
  406. RotateLeft
  407.  
  408.     formal declaration:
  409.         BitMap* RotateLeft(BitMap* bits);
  410.     
  411.     arguments:
  412.         bits    a bitmap pointer
  413.     
  414.     return value:
  415.         a newly created bitmap pointer containing the image
  416.         from the bitmap pointer parameter rotated 90 degrees
  417.         to the left. 
  418.         if an error occurs, RotateLeft will return the value NULL.
  419.         
  420.     description:
  421.         RotateLeft creates a new bitmap containing the image
  422.         stored in the parameter bitmap pointer rotated 90 degrees
  423.         to the left.  The resulting bitmap is appropriately sized:
  424.         i.e. if the source bitmap is 100 pixels wide and 200 pixels tall,
  425.         then the result bitmap pointer will be 200 pixels wide and 100
  426.         pixels tall.  
  427.  
  428.     example application:
  429.         The example creates a new bitmap pointer containing the image
  430.         stored in the original bitmap rotated 90 degrees to the left
  431.         before copying the image to the current grafport.
  432.         
  433.         {   BitMap *the_bits;
  434.             BitMap *rotated_bits;
  435.             Rect bounds;
  436.             
  437.             the_bits = NewBitMap(100, 200);
  438.             if (the_bits != NULL) {
  439.             
  440.                 /* here we would draw something into the_bits */
  441.                 
  442.                 rotated_bits = RotateLeft(the_bits);
  443.                 
  444.                 if (rotated_bits != NULL) {
  445.                     bounds = (*rotated_bits)->bounds;
  446.                     PlotMap(rotated_bits, 0, 0, srcCopy);
  447.                     KillBitMap(rotated_bits);
  448.                 }
  449.  
  450.                 KillBitMap(the_bits);
  451.             }
  452.             
  453.     notes:
  454.         RotateLeft takes advantage of certain addressing and indexing
  455.         possibilities offered by the arrangement of the raster data
  456.         in memory.  It is faster than calling RotateBitMap and specifying
  457.         a -90 degree angle.
  458.  
  459.  
  460. FlipVertical
  461.  
  462.     formal declaration:
  463.         BitMap* FlipVertical(BitMap* bits);
  464.     
  465.     arguments:
  466.         bits    a bitmap pointer
  467.     
  468.     return value:
  469.         a newly created bitmap pointer containing the image
  470.         from the bitmap pointer parameter flipped upside down. 
  471.         if an error occurs, FlipVertical will return the value NULL.
  472.         
  473.     description:
  474.         FlipVertical creates a new bitmap containing the image
  475.         stored in the parameter bitmap pointer flipped upside
  476.         down.  The resulting bitmap will be the same size as
  477.         the original image.  
  478.  
  479.     example application:
  480.         The example creates a new bitmap pointer containing the image
  481.         stored in the original bitmap flipped upside down before
  482.         copying the new flipped image to the current grafport.
  483.         
  484.         {   BitMap *the_bits;
  485.             BitMap *flippin_bits;
  486.             Rect bounds;
  487.             
  488.             the_bits = NewBitMap(100, 200);
  489.             if (the_bits != NULL) {
  490.             
  491.                 /* here we would draw something into the_bits */
  492.                 
  493.                 flippin_bits = FlipVertical(the_bits);
  494.                 
  495.                 if (flippin_bits != NULL) {
  496.                     bounds = (*flippin_bits)->bounds;
  497.                     PlotMap(flippin_bits, 0, 0, srcCopy);
  498.                     KillBitMap(flippin_bits);
  499.                 }
  500.  
  501.                 KillBitMap(the_bits);
  502.             }
  503.             
  504.     notes:
  505.         none.
  506.  
  507.  
  508. FlipHorizontal
  509.  
  510.     formal declaration:
  511.         BitMap* FlipHorizontal(BitMap* bits);
  512.     
  513.     arguments:
  514.         bits    a bitmap pointer
  515.     
  516.     return value:
  517.         a newly created bitmap pointer containing the image
  518.         from the bitmap pointer parameter flipped horizontally. 
  519.         if an error occurs, FlipHorizontal will return the value NULL.
  520.         
  521.     description:
  522.         FlipHorizontal creates a new bitmap containing the image
  523.         stored in the parameter bitmap pointer flipped horizontally.
  524.         The resulting bitmap will be the same size as the original image.  
  525.  
  526.     example application:
  527.         The example creates a new bitmap pointer containing the image
  528.         stored in the original bitmap flipped horizontally before
  529.         copying the new flipped image to the current grafport.
  530.         
  531.         {   BitMap *the_bits;
  532.             BitMap *flippin_bits;
  533.             Rect bounds;
  534.             
  535.             the_bits = NewBitMap(100, 200);
  536.             if (the_bits != NULL) {
  537.             
  538.                 /* here we would draw something into the_bits */
  539.                 
  540.                 flippin_bits = FlipHorizontal(the_bits);
  541.                 
  542.                 if (flippin_bits != NULL) {
  543.                     bounds = (*flippin_bits)->bounds;
  544.                     PlotMap(flippin_bits, 0, 0, srcCopy);
  545.                     KillBitMap(flippin_bits);
  546.                 }
  547.  
  548.                 KillBitMap(the_bits);
  549.             }
  550.             
  551.     notes:
  552.         none.
  553.  
  554.  
  555. RotateBitMap
  556.  
  557.     formal declaration:
  558.         BitMap* RotateBitMap(BitMap* bits, short cx, short cy, float angle);
  559.     
  560.     arguments:
  561.         bits      a bitmap pointer
  562.         cx        the horizontal center of rotation
  563.         cy        the vertical center of rotation
  564.         angle     the angle (in degrees) to rotate the image. both positive
  565.                   and negative values are ok.  This is a floating point number.
  566.                 
  567.     return value:
  568.         a newly created bitmap pointer containing the image
  569.         from the bitmap pointer parameter rotated around the center
  570.         cx and cy angle degrees. 
  571.         if an error occurs, RotateBitMap will return the value NULL.
  572.         
  573.     description:
  574.         RotateBitMap creates a new bitmap containing the image from
  575.         the parameter bitmap pointer rotated angle degrees about the
  576.         center (cx, cy).  The resultant bitmap will have the same dimensions
  577.         as the parameter bitmap regardless of the angle specified.
  578.  
  579.     example application:
  580.         The example creates a new bitmap pointer containing the image
  581.         stored in the original bitmap rotated 35.5 degrees to the right
  582.         before copying the rotated image to the current grafport.
  583.         
  584.         {   BitMap *the_bits;
  585.             BitMap *round_bits;
  586.             Rect bounds;
  587.             
  588.             the_bits = NewBitMap(100, 200);
  589.             if (the_bits != NULL) {
  590.             
  591.                 /* here we would draw something into the_bits */
  592.                 
  593.                 round_bits = RotateBitMap(the_bits, 50, 100, 35.5);
  594.                 
  595.                 if (round_bits != NULL) {
  596.                     bounds = (*round_bits)->bounds;
  597.                     PlotMap(round_bits, 0, 0, srcCopy);
  598.                     KillBitMap(round_bits);
  599.                 }
  600.  
  601.                 KillBitMap(the_bits);
  602.             }
  603.             
  604.     notes:
  605.         The 68k implementation of RotateBitMap has a speedy implementation
  606.         built on top of the fixed math routines.  For more information
  607.         about fixed math refer to the Mathematical and Logical Utilities
  608.         chapter of Inside Macintosh: Operating System Utilities.
  609.  
  610.  
  611. DuplicateBitMap
  612.  
  613.     formal declaration:
  614.         BitMap* DuplicateBitMap(BitMap* bits);
  615.     
  616.     arguments:
  617.         bits    a bitmap pointer
  618.     
  619.     return value:
  620.         a newly created bitmap pointer containing an
  621.         exact duplicate of the bitmap parameter.
  622.         if an error occurs, DuplicateBitMap will return the value NULL.
  623.         
  624.     description:
  625.         DuplicateBitMap creates a copy of the bitmap parameter.
  626.  
  627.     example application:
  628.         In this example, we make a new bitmap, duplicate it, and then
  629.         dispose of the resulting bitmaps.
  630.         
  631.         {   BitMap *the_bits;
  632.             BitMap *other_bits;
  633.             
  634.             the_bits = NewBitMap(100, 200);
  635.             if (the_bits != NULL) {
  636.             
  637.                 other_bits = DuplicateBitMap(the_bits); 
  638.                 if (other_bits != NULL) {
  639.                 
  640.                     KillBitMap(other_bits);
  641.                 }
  642.                 
  643.                 KillBitMap(the_bits);
  644.             }
  645.             
  646.     notes:
  647.         none.
  648.  
  649.  
  650. PaintBucketBitMap
  651.  
  652.     formal declaration:
  653.         BitMap* PaintBucketBitMap(BitMap* bits, short h, short v);
  654.     
  655.     arguments:
  656.         bits     a bitmap pointer
  657.         h        the horizontal position to start painting
  658.         v        the vertical position to start painting
  659.     
  660.     return value:
  661.         a newly created bitmap pointer containing an ones in every
  662.         pixel where paint would not leak out starting from the point
  663.         (h, v).
  664.         if an error occurs, PaintBucketBitMap will return the value NULL.
  665.         
  666.     description:
  667.         PaintBucketBitMap works like the paint bucket tool found in
  668.         most graphical applications.  It calls the routine SeedFill
  669.         and to fill in the image information in the resulting bitmap
  670.         pointer.
  671.  
  672.     example application:
  673.         In this example, we make a new bitmap and create a mask bitmap
  674.         using the PaintBucketBitMap routine starting at the point (50,50).
  675.         
  676.         {   BitMap *the_bits;
  677.             BitMap *paint_bits;
  678.             
  679.             the_bits = NewBitMap(100, 200);
  680.             if (the_bits != NULL) {
  681.             
  682.                 /* here, we would normally draw something in the bitmap */
  683.                 
  684.                 paint_bits = PaintBucketBitMap(the_bits, 50, 50); 
  685.                 
  686.                 if (paint_bits != NULL) {
  687.                 
  688.                     KillBitMap(paint_bits);
  689.                 }
  690.                 
  691.                 KillBitMap(the_bits);
  692.             }
  693.             
  694.     notes:
  695.         PaintBucketBitMap calls SeedFill.  For further information about
  696.         SeedFill refer to page 3-109 in the QuickDraw Drawing chapter of
  697.         Inside Macintosh: Imaging With QuickDraw.
  698.  
  699.  
  700. LassoBitMap
  701.  
  702.     formal declaration:
  703.         BitMap* LassoBitMap(BitMap* bits);
  704.     
  705.     arguments:
  706.         bits    a bitmap pointer
  707.     
  708.     return value:
  709.         a newly created bitmap pointer containing an ones in every
  710.         pixel where paint would not leak in from the edges of the
  711.         bitmap.
  712.         if an error occurs, LassoBitMap will return the value NULL.
  713.         
  714.     description:
  715.         LassoBitMap works like the lasso bucket tool found in
  716.         most graphical applications.  It calls the routine CalcMask
  717.         and to fill in the image information in the resulting bitmap
  718.         pointer.
  719.  
  720.     example application:
  721.         In this example, we make a new bitmap and create a mask bitmap
  722.         using the LassoBitMap routine.
  723.         
  724.         {   BitMap *the_bits;
  725.             BitMap *paint_bits;
  726.             
  727.             the_bits = NewBitMap(100, 200);
  728.             if (the_bits != NULL) {
  729.             
  730.                 /* here, we would normally draw something in the bitmap */
  731.                 
  732.                 paint_bits = LassoBitMap(the_bits); 
  733.                 
  734.                 if (paint_bits != NULL) {
  735.                 
  736.                     KillBitMap(paint_bits);
  737.                 }
  738.                 
  739.                 KillBitMap(the_bits);
  740.             }
  741.             
  742.     notes:
  743.         LassoBitMap calls CalcMask.  For further information about
  744.         CalcMask refer to page 3-111 in the QuickDraw Drawing chapter of
  745.         Inside Macintosh: Imaging With QuickDraw.
  746.  
  747.  
  748. TraceBitMap
  749.  
  750.     formal declaration:
  751.         BitMap* TraceBitMap(BitMap* bits);
  752.     
  753.     arguments:
  754.         bits    a bitmap pointer
  755.     
  756.     return value:
  757.         a newly created bitmap pointer containing containing the original
  758.         image with the edges traced.
  759.         if an error occurs, TraceBitMap will return the value NULL.
  760.         
  761.     description:
  762.         TraceBitMap performs the 'trace edges' command found in
  763.         many graphical applications returning a new bitmap
  764.         containing the traced image..
  765.  
  766.     example application:
  767.         In this example, we make a new bitmap and create a new bitmap
  768.         containing the traced image.
  769.         
  770.         {   BitMap *the_bits;
  771.             BitMap *traced_bits;
  772.             
  773.             the_bits = NewBitMap(100, 200);
  774.             if (the_bits != NULL) {
  775.             
  776.                 /* here, we would normally draw something in the bitmap */
  777.                 
  778.                 traced_bits = TraceBitMap(the_bits); 
  779.                 
  780.                 if (traced_bits != NULL) {
  781.                 
  782.                     KillBitMap(traced_bits);
  783.                 }
  784.                 
  785.                 KillBitMap(the_bits);
  786.             }
  787.             
  788.     notes:
  789.         none.
  790.  
  791.  
  792. EqualBitMaps
  793.  
  794.     formal declaration:
  795.         Boolean EqualBitMaps(BitMap* a, BitMap* b);
  796.     
  797.     arguments:
  798.         a    a bitmap pointer
  799.         b    a bitmap pointer
  800.     
  801.     return value:
  802.         true or false.
  803.         
  804.     description:
  805.         returns true if the two bitmaps are the same size and
  806.         contain the same image content.  returns false if either
  807.         bitmap is NULL.
  808.  
  809.     example application:
  810.         In this example, we make a new bitmap and create a two bitmaps
  811.         and compare them by calling EqualBitMaps.
  812.         
  813.         {   BitMap *the_bits;
  814.             BitMap *other_bits;
  815.             
  816.             the_bits = NewBitMap(100, 200);
  817.             if (the_bits != NULL) {
  818.             
  819.                 other_bits = TraceBitMap(the_bits); 
  820.                     
  821.                 if (other_bits != NULL) {
  822.                     
  823.                     /* here, we would normally draw something in the bitmaps */
  824.                     
  825.                     if (EqualBitMaps(other_bits, the_bits)) {
  826.                     
  827.                         /* they're the same *blink* */
  828.                         
  829.                     }
  830.                     
  831.                     KillBitMap(other_bits);
  832.                 }
  833.                 KillBitMap(the_bits);
  834.             }
  835.             
  836.     notes:
  837.         EqualBitMaps takes into account that either bitmap may have
  838.         different rowBytes values, and the possibility that garbage
  839.         values may be stored in the unused bits off to the right
  840.         of the boundary rectangle.
  841.  
  842.  
  843. PICTToBitMap
  844.  
  845.     formal declaration:
  846.         BitMap* PICTToBitMap(PicHandle pic);
  847.     
  848.     arguments:
  849.         pic        a handle to a QuickDraw picture
  850.     
  851.     return value:
  852.         a newly created bitmap pointer containing a black and white
  853.         representation of the image drawn by the quickdraw picture
  854.         parameter.
  855.         if an error occurs, PICTToBitMap will return the value NULL.
  856.         
  857.     description:
  858.         PICTToBitMap creates a new bitmap pointer the using the size
  859.         information provided in the QuickDraw picture pointer parameter
  860.         and draws the picture in the bitmap before returning the bitmap.
  861.  
  862.     example application:
  863.         In this example, we call GetPicture to retrieve a picture from
  864.         a resource file and then we convert it to a bitmap by calling
  865.         the routine PICTToBitMap.
  866.         
  867.         {   PicHandle the_picture;
  868.             BitMap *the_bits;
  869.             
  870.             the_picture = GetPicture(128);
  871.             if (the_picture != NULL) {
  872.             
  873.                 the_bits = PICTToBitMap(the_picture);
  874.                 
  875.                 if (the_bits != NULL) {
  876.                     
  877.                     /* at this point, the the_bits contains the picture */
  878.                     
  879.                     KillBitMap(the_bits);
  880.                 }
  881.             
  882.             }
  883.             
  884.     notes:
  885.         none.
  886.  
  887.  
  888. BitMapToPICT
  889.  
  890.     formal declaration:
  891.         PicHandle BitMapToPICT(BitMap* bits);
  892.     
  893.     arguments:
  894.         bits    a bitmap pointer
  895.     
  896.     return value:
  897.         a handle to a QuickDraw picture. 
  898.         if an error occurs, the picture's picFrame will be
  899.         an empty rectangle.
  900.         
  901.     description:
  902.         BitMapToPICT returns a QuickDraw picture that will draw the
  903.         image stored in the bitmap.  BitMapToPICT is the inverse
  904.         of PICTToBitMap.
  905.  
  906.     example application:
  907.         In this example, we create a bitmap and convert it into a QuickDraw
  908.         picture.
  909.         
  910.         {   PicHandle the_picture;
  911.             BitMap *the_bits;
  912.             
  913.             the_bits = NewBitMap(100, 200);
  914.             if (the_bits != NULL) {
  915.             
  916.                 the_picture = BitMapToPICT(the_bits);
  917.                 
  918.                 KillBitMap(the_bits);
  919.             
  920.             }
  921.             
  922.     notes:
  923.         QuickDraw pictures are a good way to store image data.
  924.  
  925.  
  926. BitMapAND
  927.  
  928.     formal declaration:
  929.         BitMap* BitMapAND(BitMap* a, BitMap* b);
  930.     
  931.     arguments:
  932.         a        a bitmap pointer
  933.         b        a bitmap pointer
  934.     
  935.     return value:
  936.         a bitmap pointer containing the logical result of ANDing the
  937.         raster data from bitmap a with the raster data from bitmap b. 
  938.         if an error occurs, NULL is returned.
  939.         
  940.     description:
  941.         BitMapAND logically ANDs the raster data of two bitmap pointers
  942.         returning a new bitmap pointer containing the result.  The two
  943.         parameter bitmaps must have identical dimensions.
  944.  
  945.     example application:
  946.         In this example, we create two bitmaps and AND them together creating
  947.         a third bitmap.
  948.         
  949.         {   BitMap *a=NULL, *b=NULL, *c=NULL;
  950.             
  951.             a = NewBitMap(100, 100);
  952.             if (a == NULL) goto my_error_handler;
  953.             b = NewBitMap(100, 100);
  954.             if (b == NULL) goto my_error_handler;
  955.             
  956.             c = BitMapAND(a, b);
  957.             if (c == NULL) goto my_error_handler;
  958.             
  959.                 /* at this point, c contains the result of logically ANDing
  960.                 the bitmaps a and b */
  961.         
  962.         my_error_handler:
  963.             if (a != NULL) KillBitMap(a);
  964.             if (b != NULL) KillBitMap(b);
  965.             if (c != NULL) KillBitMap(c);
  966.         }
  967.         
  968.     notes:
  969.         useful for calculating the intersection of two sets of bits.
  970.  
  971.  
  972. BitMapOR
  973.  
  974.     formal declaration:
  975.         BitMap* BitMapOR(BitMap* a, BitMap* b);
  976.     
  977.     arguments:
  978.         a        a bitmap pointer
  979.         b        a bitmap pointer
  980.     
  981.     return value:
  982.         a bitmap pointer containing the logical result of ORing the
  983.         raster data from bitmap a with the raster data from bitmap b. 
  984.         if an error occurs, NULL is returned.
  985.         
  986.     description:
  987.         BitMapOR logically ORs the raster data of two bitmap pointers
  988.         returning a new bitmap pointer containing the result.  The two
  989.         parameter bitmaps must have identical dimensions.
  990.  
  991.     example application:
  992.         In this example, we create two bitmaps and OR them together creating
  993.         a third bitmap.
  994.         
  995.         {   BitMap *a=NULL, *b=NULL, *c=NULL;
  996.             
  997.             a = NewBitMap(100, 100);
  998.             if (a == NULL) goto my_error_handler;
  999.             b = NewBitMap(100, 100);
  1000.             if (b == NULL) goto my_error_handler;
  1001.             
  1002.             c = BitMapOR(a, b);
  1003.             if (c == NULL) goto my_error_handler;
  1004.             
  1005.                 /* at this point, c contains the result of logically ORing
  1006.                 the bitmaps a and b */
  1007.         
  1008.         my_error_handler:
  1009.             if (a != NULL) KillBitMap(a);
  1010.             if (b != NULL) KillBitMap(b);
  1011.             if (c != NULL) KillBitMap(c);
  1012.         }
  1013.         
  1014.     notes:
  1015.         useful for calculating the union of two sets of bits.
  1016.  
  1017.  
  1018. BitMapXOR
  1019.  
  1020.     formal declaration:
  1021.         BitMap* BitMapXOR(BitMap* a, BitMap* b);
  1022.     
  1023.     arguments:
  1024.         a        a bitmap pointer
  1025.         b        a bitmap pointer
  1026.     
  1027.     return value:
  1028.         a bitmap pointer containing the logical result of XORing the
  1029.         raster data from bitmap a with the raster data from bitmap b. 
  1030.         if an error occurs, NULL is returned.
  1031.         
  1032.     description:
  1033.         BitMapXOR logically XORs the raster data of two bitmap pointers
  1034.         returning a new bitmap pointer containing the result.  The two
  1035.         parameter bitmaps must have identical dimensions.
  1036.  
  1037.     example application:
  1038.         In this example, we create two bitmaps and XOR them together creating
  1039.         a third bitmap.
  1040.         
  1041.         {   BitMap *a=NULL, *b=NULL, *c=NULL;
  1042.             
  1043.             a = NewBitMap(100, 100);
  1044.             if (a == NULL) goto my_error_handler;
  1045.             b = NewBitMap(100, 100);
  1046.             if (b == NULL) goto my_error_handler;
  1047.             
  1048.             c = BitMapXOR(a, b);
  1049.             if (c == NULL) goto my_error_handler;
  1050.             
  1051.                 /* at this point, c contains the result of logically XORing
  1052.                 the bitmaps a and b */
  1053.         
  1054.         my_error_handler:
  1055.             if (a != NULL) KillBitMap(a);
  1056.             if (b != NULL) KillBitMap(b);
  1057.             if (c != NULL) KillBitMap(c);
  1058.         }
  1059.         
  1060.     notes:
  1061.         useful for calculating the difference of two sets of bits.
  1062.  
  1063.  
  1064. BitMapNOT
  1065.  
  1066.     formal declaration:
  1067.         BitMap* BitMapNOT(BitMap* a);
  1068.     
  1069.     arguments:
  1070.         a        a bitmap pointer
  1071.     
  1072.     return value:
  1073.         a bitmap pointer containing the logical result of complementing the
  1074.         raster data from bitmap a. 
  1075.         if an error occurs, NULL is returned.
  1076.         
  1077.     description:
  1078.         BitMapNOT returns a new bitmap pointer containing the inverse
  1079.         of the raster image contained in the bitmap pointer a.
  1080.  
  1081.     example application:
  1082.         In this example, we create a bitmap and it's complement.
  1083.         
  1084.         {   BitMap *a=NULL, *b=NULL;
  1085.             
  1086.             a = NewBitMap(100, 100);
  1087.             if (a == NULL) goto my_error_handler;
  1088.             
  1089.             b = BitMapNOT(a);
  1090.             if (b == NULL) goto my_error_handler;
  1091.             
  1092.                 /* at this point, b contains the compliment of a */
  1093.         
  1094.         my_error_handler:
  1095.             if (a != NULL) KillBitMap(a);
  1096.             if (b != NULL) KillBitMap(b);
  1097.         }
  1098.         
  1099.     notes:
  1100.         useful for calculating the complement of a set of bits.
  1101.  
  1102.  
  1103. BitMapTest
  1104.  
  1105.     formal declaration:
  1106.         Boolean BitMapTest(BitMap* bits, short h, short v);
  1107.     
  1108.     arguments:
  1109.         bits     a bitmap pointer
  1110.         h        the horizontal position of the pixel to test
  1111.         v        the vertical position of the pixel to test
  1112.         
  1113.     return value:
  1114.         true if the pixel is 1, false if the pixel is 0.
  1115.         
  1116.     description:
  1117.         BitMapTest tests the value of the pixel at the location (h,v)
  1118.         returning true if the pixel is 1, and false if the pixel
  1119.         is zero.
  1120.  
  1121.     example application:
  1122.         In this example, we create a bitmap and test the pixel
  1123.         located at (25, 32).
  1124.         
  1125.         {   BitMap *bits=NULL;
  1126.             
  1127.             bits = NewBitMap(100, 100);
  1128.             if (bits == NULL) goto my_error_handler;
  1129.             
  1130.             ....
  1131.             
  1132.             if (BitMapTest(bits, 25, 32)) {
  1133.                 /* the pixel is 1 */
  1134.             } else {
  1135.                 /* the pixel is 0 */
  1136.             }
  1137.  
  1138.         my_error_handler:
  1139.             if (bits != NULL) KillBitMap(bits);
  1140.         }
  1141.  
  1142.     notes:
  1143.         attempting to test a point outside of the bitmap's bounds
  1144.         will produce unpredictable results.
  1145.  
  1146.  
  1147. BitMapSet
  1148.  
  1149.     formal declaration:
  1150.         void BitMapSet(BitMap* bits, short h, short v);
  1151.     
  1152.     arguments:
  1153.         bits     a bitmap pointer
  1154.         h        the horizontal position of the pixel to set
  1155.         v        the vertical position of the pixel to set
  1156.     
  1157.     return value:
  1158.         none.
  1159.         
  1160.     description:
  1161.         BitMapSet sets the value of the pixel at the location (h,v) to 1.
  1162.  
  1163.     example application:
  1164.         In this example, we create a bitmap and set the pixel
  1165.         located at (25, 32) to the value 1.
  1166.         
  1167.         {   BitMap *bits=NULL;
  1168.             
  1169.             bits = NewBitMap(100, 100);
  1170.             if (bits == NULL) goto my_error_handler;
  1171.             
  1172.             ....
  1173.             
  1174.             BitMapSet(bits, 25, 32);
  1175.  
  1176.         my_error_handler:
  1177.             if (bits != NULL) KillBitMap(bits);
  1178.         }
  1179.  
  1180.     notes:
  1181.         attempting to set a pixel outside of the bitmap's bounds
  1182.         will produce unpredictable results and may even crash your
  1183.         computer by overwriting something important like the operating
  1184.         system or your program or something like that.
  1185.  
  1186.  
  1187. BitMapClear
  1188.  
  1189.     formal declaration:
  1190.         void BitMapClear(BitMap* bits, short h, short v);
  1191.     
  1192.     arguments:
  1193.         bits     a bitmap pointer
  1194.         h        the horizontal position of the pixel to set
  1195.         v        the vertical position of the pixel to set
  1196.     
  1197.     return value:
  1198.         none.
  1199.         
  1200.     description:
  1201.         BitMapClear clears the value of the pixel at the location (h,v)
  1202.         to 0.
  1203.  
  1204.     example application:
  1205.         In this example, we create a bitmap and set the pixel
  1206.         located at (25, 32) to the value 0.
  1207.         
  1208.         {   BitMap *bits=NULL;
  1209.             
  1210.             bits = NewBitMap(100, 100);
  1211.             if (bits == NULL) goto my_error_handler;
  1212.             
  1213.             ....
  1214.             
  1215.             BitMapClear(bits, 25, 32);
  1216.  
  1217.         my_error_handler:
  1218.             if (bits != NULL) KillBitMap(bits);
  1219.         }
  1220.  
  1221.     notes:
  1222.         attempting to clear a pixel outside of the bitmap's bounds
  1223.         will produce unpredictable results and may even crash your
  1224.         computer by overwriting something important like the operating
  1225.         system or your program or something like that.
  1226.  
  1227.  
  1228. BitMapToggle
  1229.  
  1230.     formal declaration:
  1231.         Boolean BitMapToggle(BitMap* bits, short h, short v);
  1232.     
  1233.     arguments:
  1234.         bits     a bitmap pointer
  1235.         h        the horizontal position of the pixel to set
  1236.         v        the vertical position of the pixel to set
  1237.     
  1238.     return value:
  1239.         a boolean value indicating the state of the pixel
  1240.         after the toggle operation.  i.e. if the pixel is
  1241.         set to the value 1, true is returned.  If the pixel
  1242.         is set to the value 0, false is returned.
  1243.         
  1244.     description:
  1245.         BitMapToggle inverts the value of the pixel at the location (h,v)
  1246.         returning true if the pixel is set to 1 or false if the pixel
  1247.         is set to 0.
  1248.  
  1249.     example application:
  1250.         In this example, we create a bitmap and invert the pixel
  1251.         located at (25, 32).
  1252.         
  1253.         {   BitMap *bits=NULL;
  1254.             
  1255.             bits = NewBitMap(100, 100);
  1256.             if (bits == NULL) goto my_error_handler;
  1257.             
  1258.             ....
  1259.             
  1260.             BitMapToggle(bits, 25, 32);
  1261.  
  1262.         my_error_handler:
  1263.             if (bits != NULL) KillBitMap(bits);
  1264.         }
  1265.  
  1266.     notes:
  1267.         attempting to toggle a pixel outside of the bitmap's bounds
  1268.         will produce unpredictable results and may even crash your
  1269.         computer by overwriting something important like the operating
  1270.         system or your program or something like that.
  1271.  
  1272.  
  1273. NewBMP
  1274.  
  1275.     formal declaration:
  1276.         BitMapPort* NewBMP(BitMap* bits);
  1277.     
  1278.     arguments:
  1279.         bits    a bitmap pointer
  1280.     
  1281.     return value:
  1282.         a pointer to a BitMapPort data structure.
  1283.         if an error occurs, NULL is returned.
  1284.         
  1285.     description:
  1286.         NewBMP is called by the WithBitMap macro and you should
  1287.         never have to call it directly yourself.  What it does is
  1288.         it saves the original grafport, and creates a new grafport
  1289.         suitable for drawing into the bitmap.  NewBMP should be
  1290.         followed by a call to DisposeBMP which will restore the
  1291.         original grafport, and dispose of the grafport that was
  1292.         created by NewBMP.
  1293.  
  1294.     example application:
  1295.         In this example, we create a bitmap and use the NewBMP to make
  1296.         a grafport.  Then we draw into it and call DisposeBMP to deallocate
  1297.         the grafport.
  1298.         
  1299.         {   BitMap *bits=NULL;
  1300.             BitMapPort *bmp=NULL;
  1301.             
  1302.             bits = NewBitMap(100, 100);
  1303.             if (bits == NULL) goto my_error_handler;
  1304.             bmp = NewBMP(bits);
  1305.             if (bmp == NULL) goto my_error_handler;
  1306.                 
  1307.                 /* after NewBMP, the grafport is set to draw into the bitmap */
  1308.             MoveTo(10,10);
  1309.             LineTo(20,20);
  1310.             DrawString("\pHello World");
  1311.  
  1312.         my_error_handler:
  1313.             if (bmp != NULL) DisposeBMP(bmp);
  1314.             if (bits != NULL) KillBitMap(bits);
  1315.             
  1316.         }
  1317.  
  1318.     notes:
  1319.         if NewBMP returns a pointer to a BitMapPort, then you must
  1320.         dispose of that pointer with a call to DisposeBMP.
  1321.  
  1322.  
  1323. DisposeBMP
  1324.  
  1325.     formal declaration:
  1326.         void DisposeBMP(BitMapPort* bmp);
  1327.     
  1328.     arguments:
  1329.         bmp        a pointer to a BitMapPort structure allocated by NewBMP
  1330.     
  1331.     return value:
  1332.         none.
  1333.         
  1334.     description:
  1335.         DisposeBMP restores the original grafport and, deallocates
  1336.         the grafport allocated for drawing into the bitmap.
  1337.         The macro WithBitMap calls this routine automatically and you will
  1338.         not normally have to call it directly.
  1339.  
  1340.     example application:
  1341.         see the example in NewBMP.
  1342.         
  1343.     notes:
  1344.         none.
  1345.  
  1346.  
  1347. WithBitMap
  1348.  
  1349.     formal declaration:
  1350.         MACRO WithBitMap(bits, bmp) { statement... }
  1351.     
  1352.     arguments:
  1353.         bits        a bitmap pointer
  1354.         bmp         a variable you have declared of type BitMapPort*
  1355.     
  1356.     return value:
  1357.         not applicable
  1358.         
  1359.     description:
  1360.         WithBitMap is a macro facility that sets up the drawing
  1361.         environment such that any drawing commands in the statement
  1362.         following the macro instantiation will draw into the bitmap
  1363.         provided as the first parameter.
  1364.  
  1365.     example application:
  1366.         In this example, we create a bitmap and use the WithBitMap
  1367.         macro to do some drawing in it.
  1368.         
  1369.         {   BitMap *bits=NULL;
  1370.             BitMapPort *bmp;
  1371.             
  1372.             bits = NewBitMap(100, 100);
  1373.             if (bits == NULL) goto my_error_handler;
  1374.             
  1375.             WithBitMap(bits, bmp) {
  1376.                 MoveTo(10,10);
  1377.                 TextFont(geneva);
  1378.                 TextSize(12);
  1379.                 DrawString("\pHello World");
  1380.             }
  1381.  
  1382.         my_error_handler:
  1383.             if (bits != NULL) KillBitMap(bits);
  1384.             
  1385.         }
  1386.  
  1387.     notes:
  1388.         none.
  1389.  
  1390.  
  1391. PlotBitMap
  1392.  
  1393.     formal declaration:
  1394.         void PlotBitMap(BitMap* bits, short h, short v);
  1395.     
  1396.     arguments:
  1397.         bits        a bitmap pointer
  1398.         h           the horizontal location where the bitmap is drawn
  1399.         v           the horizontal location where the bitmap is drawn
  1400.         mode        transfer mode passed to copybits
  1401.     
  1402.     return value:
  1403.         none.
  1404.         
  1405.     description:
  1406.         PlotBitMap provides a simple interface for drawing a bitmap in
  1407.         the current grafport.  The bitmap is drawn with the top left corner
  1408.         aligned with the point (h,v) using the indicated transfer mode.
  1409.  
  1410.     example application:
  1411.         In this example, we create a bitmap and use the WithBitMap
  1412.         macro to do some drawing in it, and then we copy the result
  1413.         to the current grafport at the location (75, 23) using the
  1414.         PlotBitMap routine.
  1415.         
  1416.         {   BitMap *bits=NULL;
  1417.             BitMapPort *bmp;
  1418.             
  1419.             bits = NewBitMap(100, 100);
  1420.             if (bits == NULL) goto my_error_handler;
  1421.             
  1422.             WithBitMap(bits, bmp) {
  1423.                 MoveTo(10,10);
  1424.                 TextFont(geneva);
  1425.                 TextSize(12);
  1426.                 DrawString("\pHello World");
  1427.             }
  1428.             
  1429.            PlotBitMap(bits, 75, 23, srcCopy);
  1430.  
  1431.         my_error_handler:
  1432.             if (bits != NULL) KillBitMap(bits);
  1433.             
  1434.         }
  1435.  
  1436.     notes:
  1437.         PlotBitMap calls CopyBits.
  1438.  
  1439.  
  1440. StringToBitMap
  1441.  
  1442.     formal declaration:
  1443.         BitMap* StringToBitMap(short font, short size, short face, StringPtr s);
  1444.     
  1445.     arguments:
  1446.         font        a font number
  1447.         size        the font size
  1448.         face        the font style
  1449.                     (normal,bold,italic,underline,outline,shadow,condense,extend)
  1450.         s           a pointer to a pascal string
  1451.  
  1452.     return value:
  1453.         a bitmap pointer
  1454.         
  1455.     description:
  1456.         StringToBitMap converts the string pointed to by s into a bitmap
  1457.         drawing the string onto an appropriately sized bitmap for the
  1458.         given font, size, and style(face).  StringToBitMap is useful for
  1459.         converting strings to bitmap so rotation can be applied with
  1460.         RotateRight or RotateLeft before it is displayed.  StringToBitMap
  1461.         preserves the current grafport.
  1462.  
  1463.     example application:
  1464.         In this example, we create a bitmap pointer containing
  1465.         the string "\pHello World" (using bold, underlined,
  1466.         24 point geneva font), rotate it 90 degrees to the
  1467.         right, and draw the result in the current grafport
  1468.         at the location (110,34) using the PlotBitMap routine.
  1469.         
  1470.         {   BitMap *bits = NULL, *right_bits = NULL;
  1471.             
  1472.             bits = StringToBitMap(geneva, 24, bold + underlined, "\pHello World");
  1473.             if (bits == NULL) goto my_error_handler;
  1474.             
  1475.             right_bits = RotateRight(bits);
  1476.             if (right_bits == NULL) goto my_error_handler;
  1477.             
  1478.             PlotBitMap(right_bits, 110, 34);
  1479.  
  1480.         my_error_handler:
  1481.             if (bits != NULL) KillBitMap(bits);
  1482.             if (right_bits != NULL) KillBitMap(right_bits);
  1483.             
  1484.         }
  1485.  
  1486.     notes:
  1487.         none.
  1488.  
  1489.  
  1490. file BitMap.txt Copyright (C) 1996 by John Montbriand.  All Rights Reserved.
  1491.  
  1492. end of file
  1493.